<template>
  <div class="Administrator" v-loading="loading">
    <div class="first">
      <div class="first-block">
        <div class="first-block-list" v-for="(item, index) in 4" :key="index">
          <div class="first-block-list-title">
            {{
              index == 0
                ? "id"
                : index == 1
                ? "id名称"
                : index == 2
                ? "操作类型"
                : index == 3
                ? "操作日期"
                : index == 4
                ? ""
                : ""
            }}
          </div>
          <div class="first-block-list-input" v-if="index != 3">
            <el-input
              v-if="index == 0"
              placeholder="请输入id"
              v-model="userId"
              clearable
            >
            </el-input>
            <el-input
              v-if="index == 1"
              placeholder="请输入id名称"
              v-model="userName"
              clearable
            >
            </el-input>

            <el-select
              v-if="index == 2"
              v-model="operationType"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in operationList"
                :key="item.label"
                :label="item.label"
                :value="item.label"
              >
              </el-option>
            </el-select>

            <!-- <el-select
              v-if="index == 3"
              v-model="operationModule"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in operationModuleList"
                :key="item.value"
                :label="item.label"
                :value="item.label"
              >
              </el-option>
            </el-select> -->
          </div>

          <div class="first-block-list-picker" v-else>
            <el-date-picker
              v-model="operationTime"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator=""
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </div>
        </div>
      </div>
      <div class="first-button">
        <div class="first-button-left" @click="detailInquire">查询</div>
        <div class="first-button-right" @click="detailReset">重置</div>
      </div>
    </div>

    <div class="second">
      <div class="second-text">查询结果</div>
      <div class="second-table">
        <el-table
          :data="firstTable"
          tooltip-effect="dark"
          @selection-change="handleSelectionChange"
          style="width: 100%; cursor: pointer"
          :header-cell-style="{
            color: '#949494',
            backgroundColor: '#F9F9F9',
          }"
          ><!-- 自定义暂无数据 -->
          <template slot="empty">
            <div class="empty-block">
              <img
                class="empty-block-img"
                src="../../assets/common/common-empty.png"
              />
              <div class="empty-block-text">暂无数据～</div>
            </div>
          </template>
          <el-table-column
            type="selection"
            width="100"
            align="center"
          ></el-table-column>
          <el-table-column prop="adminId" label="id" width="80"></el-table-column>
          <el-table-column prop="userName" label="id名称" width="180"></el-table-column>
          <el-table-column prop="title" label="操作类型"></el-table-column>
          <el-table-column prop="model" label="操作模块"></el-table-column>
          <el-table-column
            prop="content"
            label="操作内容"
            width="377"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            label="操作时间"
            width="171"
          ></el-table-column>
          <el-table-column prop="ip" label="操作IP"></el-table-column>
        </el-table>
      </div>

      <div class="second-pagination">
        <div class="pagination-left">共{{ totalNum }}条数据</div>

        <div class="pagination-right">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 30, 50, 100]"
            :page-size="10"
            layout="sizes, prev, pager, next, jumper"
            :total="totalNum"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getmanagerLog } from "../../api/jurisdiction";

export default {
  data() {
    return {
      // 第一区域参数 id
      userId: "",
      // 第一区域 id名称
      userName: "",
      // 操作类型
      operationType: "",
      operationList: [
        {
          value: 0,
          label: "新增",
        },
        {
          value: 1,
          label: "修改",
        },
        {
          value: 2,
          label: "删除",
        },
        {
          value: 3,
          label: "查看",
        },
      ],
      // 操作模块
      operationModule: "",
      operationModuleList: [
        {
          value: 0,
          label: "登录模块",
        },],
      // 操作日期
      operationTime: [],
      // 用户操作日期的时候起始值
      operationTimeA: "",
      // 用户操作日期的时候结尾值
      operationTimeB: "",
      // 第二区域
      firstTable: [],
      // 总条数
      totalNum: 0,

      // 页码
      page: 1,
      // 页数
      limit: 10,
      // 监听用户刷新
      loading: false,
      // 控制当前页面功能性按钮开关
      roleFunShow: true,
      multipleSelection: [],
    };
  },
  created() {
    // // 获取管理员接口
    this.loading = true;
    this.getmanagerLogMet();
  },
  methods: {
    // 第一区域 查询
    detailInquire() {
      this.loading = true;

      if (this.operationTime != null) {
        this.operationTimeA = this.operationTime[0];
        this.operationTimeB = this.operationTime[1];
      } else {
        this.operationTimeA = "";
        this.operationTimeB = "";
      }

      this.page = 1;

      this.$nextTick(() => {
        this.getmanagerLogMet();
      });
    },
    // 第二区域 重置
    detailReset() {
      this.loading = true;
      this.userId = "";
      this.userName = "";
      this.operationType = "";
      this.operationModule = "";
      this.operationTime = [];
      this.operationTimeB = ''
      this.operationTimeA = ''

      this.limit = 10;
      this.page = 1;

      this.getmanagerLogMet();
    },

    // 获取管理员日志数据接口
    getmanagerLogMet() {
      let params = {
        id: this.userId, // 管理员id
        phone: "", // 手机号
        userName: this.userName, // 用户名 id名称
        nickname: "", // 昵称
        position: "", // 职位
        title: this.operationType, // 操作类型 你写死字符串传就是了 三个类型
        model: '', // 操作模块
        createStartTime: this.operationTimeA, // 操作开始时间 ymdhis
        createEndTime: this.operationTimeB, // 操作结束时间ymdhis
        pageSize: this.limit, // 页码
        pageNo: this.page, // 页数
      };

      getmanagerLog(params).then((res) => {
        console.log("查看管理员日志接口", res);
        if (res.resultStatus == true) {
          this.firstTable = res.resultData.adminLogList;
          // 总条数
          this.totalNum = res.resultData.totalNum;

          this.loading = false;
        }
      });
    },
    // 表格区域点击选中 勾选对应的
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 查询当前页码多少条
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      console.log(`每页 ${val} 条`);
      this.getmanagerLogMet();
    },
    // 查询当前页
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      console.log(`当前页: ${val}`);
      this.getmanagerLogMet();
    },
  },
};
</script>

<style lang="less" scoped>
/deep/ .el-input__inner:focus {
  border-color: rgba(217, 217, 217, 1);
}

/deep/ .el-textarea__inner:focus {
  border-color: rgba(217, 217, 217, 1);
}

/deep/ .el-select .el-input.is-focus .el-input__inner {
  border-color: rgba(255, 255, 255, 0);
}

.Administrator {
  .first {
    border-radius: 10px;
    display: flex;

    .first-block {
      display: flex;
      align-items: center;

      .first-block-list {
        margin-right: 12px;
        display: flex;
        align-items: center;

        .first-block-list-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #757575;
          margin-right: 12px;
        }

        .first-block-list-input {
          width: 174px;
          height: 38px;
          background: #ffffff;
          border-radius: 4px;

          /deep/ .el-input {
            height: 38px;
          }

          /deep/ .el-input__inner {
            padding: 0 10px;
            box-sizing: border-box;
            height: 38px;
            background-color: rgba(255, 255, 255, 0);
          }

          /deep/ .el-select .el-input.is-focus .el-input__inner {
            border-color: rgba(217, 217, 217, 1);
          }
        }

        .first-block-list-picker {
          width: 385px;
          /deep/ .el-input__inner {
            height: 38px;
          }

          /deep/ .el-range-editor.el-input__inner {
            padding: 0;
            padding: 0 12px;
            box-sizing: border-box;
          }

          /deep/ .el-date-editor--daterange.el-input__inner {
            width: 100%;
          }

          /deep/ .el-date-editor .el-range-separator {
            width: 26px;
            padding: 0;
            height: 32px;
            line-height: 32px;
            background-image: url("../../assets/common/activities-right.png");
            background-repeat: no-repeat;
            background-position: center;
          }
        }
      }

      .first-block-list:last-child {
        margin-right: 0;
      }
    }

    .first-button {
      display: flex;
      margin-left: 10px;

      .first-button-left,
      .first-button-right {
        width: 66px;
        height: 35px;
        background: #2588fa;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;

        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #ffffff;
        cursor: pointer;
        border: 1px solid #2588fa;
      }

      .first-button-right {
        background: #ffffff;
        color: #949494;
        margin-left: 12px;
        border: 1px solid #dedede;
      }
    }
  }

  .second {
    border-radius: 10px;
    margin-top: 24px;
    .second-text {
      display: flex;
      align-items: center;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      color: #222222;
      margin-bottom: 10px;
    }

    .second-table {
      /deep/ .el-table thead {
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 600;
        color: #333333;
        background: #d8d8d8;
      }

      /deep/ .el-table tr {
        height: 46px;
      }

      .empty-block {
        margin-top: 62px;
        padding-bottom: 40px;

        .empty-block-img {
          width: 130px;
          height: 130px;
          margin: 0 auto;
        }

        .empty-block-text {
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          margin-top: 10px;
          height: 17px;
          line-height: 17px;
        }
      }
    }

    .second-pagination {
      height: 75px;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .pagination-left {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 15px;
        color: #949494;
      }

      .pagination-right {
        /deep/ .el-pagination .btn-prev {
          padding: 0;
          width: 30px;
          height: 30px;
          background: #f4f5f9;
          border-radius: 2px;
          border: 1px solid #d9d9d9;
          margin-right: 8px;
        }

        /deep/ .el-pagination .btn-next {
          padding: 0;
          width: 30px;
          height: 30px;
          background: #f4f5f9;
          border-radius: 2px;
          border: 1px solid #d9d9d9;
        }

        /deep/ .el-pager li {
          padding: 0;
          width: 30px;
          height: 30px;
          border-radius: 2px;
          background: #f4f5f9;
          border: 1px solid #d9d9d9;
          line-height: 30px;
          margin-right: 8px;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #949494;
        }

        /deep/ .el-pager li.active {
          background: #2588fa;
          color: #ffffff;
        }

        /deep/ .el-input--mini .el-input__inner {
          height: 30px;
          background: #f4f5f9;
        }

        /deep/ .el-input__inner {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.65);
        }
      }
    }
  }
}
</style>
